/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022. All rights reserved.
 *
 */

import path from 'path';

import { BuildDirConst } from '../../const/build-directory-const.js';
import { CommonConst } from '../../const/common-const.js';
import { ModuleJson } from '../../options/configure/module-json-options.js';
import { getJson5Obj } from '../../utils/json-util.js';
import { resModelLoader } from '../../utils/loader/file/res-model-loader.js';

import { CoreResModelImpl } from './core-res-model-impl.js';
import { ModuleTargetRes } from './res-model.js';

/**
 * Stage Module 的不同target对应的资源集合
 *
 * @since 2022/2/23
 */
export class ModuleTargetResImpl extends CoreResModelImpl implements ModuleTargetRes {
  constructor(sourceSetRoot: string) {
    super(path.resolve(sourceSetRoot, CommonConst.MODULE_JSON5), path.resolve(sourceSetRoot, BuildDirConst.RESTOOL_BUILD_RESOURCES));
  }

  getModuleJsonOpt(): ModuleJson.ModuleOptObj {
    return resModelLoader.getModuleJson(this.getJsonPath());
  }

  getFormJsonOpt(formPath: string): ModuleJson.FormsObj {
    return getJson5Obj(path.resolve(this.getResourcePath(), formPath));
  }
}
